//
//  TradeService.m
//  BTCoin
//
//  Created by Robin on 16/03/2018.
//  Copyright © 2018 Robin. All rights reserved.
//

#import "TradeService.h"

@implementation TradeService

DEFINE_SINGLETON_FOR_CLASS(TradeService)

#pragma mark - 资金账号
- (void)accountbank:(successResponseBlock)successBlock fail:(failResponseBlock)failBlock {
    NSString * urlStr = [NSString stringWithFormat:@"%@/financial/accountbank.do",BaseHttpUrl];
    
    [BaseService post:urlStr headerDictionay:[[UserInfo sharedUserInfo] getHeaderDic]  timeout:SERVICETIMEOUT success:^(id responseObject) {
        NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingAllowFragments error:nil removingNulls:YES ignoreArrays:NO];
        successBlock(dict);
    } fail:^(NSError *error) {
        failBlock(error);
    }];
}

#pragma mark - 提现管理
- (void)accountcoin:(NSDictionary *)parDict success:(successResponseBlock)successBlock fail:(failResponseBlock)failBlock {
    NSString * para = [parDict toHttpUrlPara];
    NSString * urlStr = [NSString stringWithFormat:@"%@/financial/accountcoin.do?%@",BaseHttpUrl,para];
    
    [BaseService post:urlStr headerDictionay:[[UserInfo sharedUserInfo] getHeaderDic]  timeout:SERVICETIMEOUT success:^(id responseObject) {
        NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingAllowFragments error:nil removingNulls:YES ignoreArrays:NO];
        successBlock(dict);
    } fail:^(NSError *error) {
        failBlock(error);
    }];
}

#pragma mark - 实名认证
- (void)realCertification:(successResponseBlock)successBlock fail:(failResponseBlock)failBlock {
    NSString * urlStr = [NSString stringWithFormat:@"%@/user/realCertification.do",BaseHttpUrl];
    
    [BaseService post:urlStr headerDictionay:[[UserInfo sharedUserInfo] getHeaderDic]  timeout:SERVICETIMEOUT success:^(id responseObject) {
        NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingAllowFragments error:nil removingNulls:YES ignoreArrays:NO];
        successBlock(dict);
    } fail:^(NSError *error) {
        failBlock(error);
    }];
}

#pragma mark - 推广记录
- (void)mydivide:(NSDictionary *)parDict success:(successResponseBlock)successBlock fail:(failResponseBlock)failBlock {
    NSString * para = [parDict toHttpUrlPara];
    NSString * urlStr = [NSString stringWithFormat:@"%@/introl/mydivide.do?%@",BaseHttpUrl,para];
    
    [BaseService post:urlStr headerDictionay:[[UserInfo sharedUserInfo] getHeaderDic]  timeout:SERVICETIMEOUT success:^(id responseObject) {
        NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingAllowFragments error:nil removingNulls:YES ignoreArrays:NO];
        successBlock(dict);
    } fail:^(NSError *error) {
        failBlock(error);
    }];
}

#pragma mark - 人民币充值
- (void)rechargeCny:(NSDictionary *)parDict success:(successResponseBlock)successBlock fail:(failResponseBlock)failBlock {
    NSString * para = [parDict toHttpUrlPara];
    NSString * urlStr = [NSString stringWithFormat:@"%@/account/rechargeCny.do?%@",BaseHttpUrl,para];
    
    [BaseService post:urlStr headerDictionay:[[UserInfo sharedUserInfo] getHeaderDic]  timeout:SERVICETIMEOUT success:^(id responseObject) {
        NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingAllowFragments error:nil removingNulls:YES ignoreArrays:NO];
        successBlock(dict);
    } fail:^(NSError *error) {
        failBlock(error);
    }];
}

#pragma mark - 人民币提现
- (void)withdrawCny:(NSDictionary *)parDict success:(successResponseBlock)successBlock fail:(failResponseBlock)failBlock {
    NSString * para = [parDict toHttpUrlPara];
    NSString * urlStr = [NSString stringWithFormat:@"%@/account/withdrawCny.do?%@",BaseHttpUrl,para];
    
    [BaseService post:urlStr headerDictionay:[[UserInfo sharedUserInfo] getHeaderDic]  timeout:SERVICETIMEOUT success:^(id responseObject) {
        NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingAllowFragments error:nil removingNulls:YES ignoreArrays:NO];
        successBlock(dict);
    } fail:^(NSError *error) {
        failBlock(error);
    }];
}

#pragma mark - 虚拟货币充值
- (void)rechargeBtc:(NSDictionary *)parDict success:(successResponseBlock)successBlock fail:(failResponseBlock)failBlock {
    NSString * para = [parDict toHttpUrlPara];
    NSString * urlStr = [NSString stringWithFormat:@"%@/account/rechargeBtc.do?%@",BaseHttpUrl,para];
    
    [BaseService post:urlStr headerDictionay:[[UserInfo sharedUserInfo] getHeaderDic]  timeout:SERVICETIMEOUT success:^(id responseObject) {
        NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingAllowFragments error:nil removingNulls:YES ignoreArrays:NO];
        successBlock(dict);
    } fail:^(NSError *error) {
        failBlock(error);
    }];
}

#pragma mark - 虚拟货币提现
- (void)withdrawBtc:(NSDictionary *)parDict success:(successResponseBlock)successBlock fail:(failResponseBlock)failBlock {
    
    NSString * para = [parDict toHttpUrlPara];
    NSString * urlStr = [NSString stringWithFormat:@"%@/account/withdrawBtc.do?%@",BaseHttpUrl,para];
    
    [BaseService post:urlStr headerDictionay:[[UserInfo sharedUserInfo] getHeaderDic]  timeout:SERVICETIMEOUT success:^(id responseObject) {
        NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingAllowFragments error:nil removingNulls:YES ignoreArrays:NO];
        successBlock(dict);
    } fail:^(NSError *error) {
        failBlock(error);
    }];
}

#pragma mark - 充值记录
- (void)accountRecord:(NSDictionary *)parDict success:(successResponseBlock)successBlock fail:(failResponseBlock)failBlock {
    
    NSString * para = [parDict toHttpUrlPara];
    NSString * urlStr = [NSString stringWithFormat:@"%@/account/record.do?%@",BaseHttpUrl,para];
    
    [BaseService post:urlStr headerDictionay:[[UserInfo sharedUserInfo] getHeaderDic]  timeout:SERVICETIMEOUT success:^(id responseObject) {
        NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingAllowFragments error:nil removingNulls:YES ignoreArrays:NO];
        successBlock(dict);
    } fail:^(NSError *error) {
        failBlock(error);
    }];
}

#pragma mark - 充值记录
- (void)refTenbody:(successResponseBlock)successBlock fail:(failResponseBlock)failBlock {
    
    NSString * urlStr = [NSString stringWithFormat:@"%@/account/refTenbody.do",BaseHttpUrl];
    
    [BaseService post:urlStr headerDictionay:[[UserInfo sharedUserInfo] getHeaderDic]  timeout:SERVICETIMEOUT success:^(id responseObject) {
        NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingAllowFragments error:nil removingNulls:YES ignoreArrays:NO];
        successBlock(dict);
    } fail:^(NSError *error) {
        failBlock(error);
    }];
}

#pragma mark - 资产记录
- (void)assetsrecord:(successResponseBlock)successBlock fail:(failResponseBlock)failBlock {
    
    NSString * urlStr = [NSString stringWithFormat:@"%@/financial/assetsrecord.do",BaseHttpUrl];
    
    [BaseService post:urlStr headerDictionay:[[UserInfo sharedUserInfo] getHeaderDic]  timeout:SERVICETIMEOUT success:^(id responseObject) {
        NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingAllowFragments error:nil removingNulls:YES ignoreArrays:NO];
        successBlock(dict);
    } fail:^(NSError *error) {
        failBlock(error);
    }];
}

#pragma mark - 交易中心
- (void)tradeCenter:(NSInteger)type success:(successResponseBlock)successBlock fail:(failResponseBlock)failBlock {
    
    NSString * urlStr = [NSString stringWithFormat:@"%@/trade/type.do?type=%ld",BaseHttpUrl,(long)type];
    
    [BaseService post:urlStr headerDictionay:[[UserInfo sharedUserInfo] getHeaderDic]  timeout:SERVICETIMEOUT success:^(id responseObject) {
        NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingAllowFragments error:nil removingNulls:YES ignoreArrays:NO];
        successBlock(dict);
    } fail:^(NSError *error) {
        failBlock(error);
    }];
}

#pragma mark - 买入/卖出
- (void)tradeCoin:(NSDictionary *)parDict success:(successResponseBlock)successBlock fail:(failResponseBlock)failBlock {
    
    NSString * para = [parDict toHttpUrlPara];
    NSString * urlStr = [NSString stringWithFormat:@"%@/trade/coin.do?%@",BaseHttpUrl,para];
    
    [BaseService post:urlStr headerDictionay:[[UserInfo sharedUserInfo] getHeaderDic]  timeout:SERVICETIMEOUT success:^(id responseObject) {
        NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingAllowFragments error:nil removingNulls:YES ignoreArrays:NO];
        successBlock(dict);
    } fail:^(NSError *error) {
        failBlock(error);
    }];
}

#pragma mark - 买入比特币
- (void)buyBtcSubmit:(NSDictionary *)parDict success:(successResponseBlock)successBlock fail:(failResponseBlock)failBlock {
    
    NSString * para = [parDict toHttpUrlPara];
    NSString * urlStr = [NSString stringWithFormat:@"%@/trade/buyBtcSubmit.do?%@",BaseHttpUrl,para];
    
    [BaseService post:urlStr headerDictionay:[[UserInfo sharedUserInfo] getHeaderDic]  timeout:SERVICETIMEOUT success:^(id responseObject) {
        NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingAllowFragments error:nil removingNulls:YES ignoreArrays:NO];
        successBlock(dict);
    } fail:^(NSError *error) {
        failBlock(error);
    }];
}

#pragma mark - 卖出比特币
- (void)sellBtcSubmit:(NSDictionary *)parDict success:(successResponseBlock)successBlock fail:(failResponseBlock)failBlock {
    
    NSString * para = [parDict toHttpUrlPara];
    NSString * urlStr = [NSString stringWithFormat:@"%@/trade/sellBtcSubmit.do?%@",BaseHttpUrl,para];
    
    [BaseService post:urlStr headerDictionay:[[UserInfo sharedUserInfo] getHeaderDic]  timeout:SERVICETIMEOUT success:^(id responseObject) {
        NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingAllowFragments error:nil removingNulls:YES ignoreArrays:NO];
        successBlock(dict);
    } fail:^(NSError *error) {
        failBlock(error);
    }];
}

#pragma mark - 委托管理、交易记录
- (void)entrust:(NSDictionary *)parDict success:(successResponseBlock)successBlock fail:(failResponseBlock)failBlock {
    
    NSString * para = [parDict toHttpUrlPara];
    NSString * urlStr = [NSString stringWithFormat:@"%@/trade/entrust.do?%@",BaseHttpUrl,para];
    
    [BaseService post:urlStr headerDictionay:[[UserInfo sharedUserInfo] getHeaderDic]  timeout:SERVICETIMEOUT success:^(id responseObject) {
        NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingAllowFragments error:nil removingNulls:YES ignoreArrays:NO];
        successBlock(dict);
    } fail:^(NSError *error) {
        failBlock(error);
    }];
}

#pragma mark - 取消交易
- (void)cancelEntrust:(NSDictionary *)parDict success:(successResponseBlock)successBlock fail:(failResponseBlock)failBlock {
    
    NSString * para = [parDict toHttpUrlPara];
    NSString * urlStr = [NSString stringWithFormat:@"%@/trade/cancelEntrust.do?%@",BaseHttpUrl,para];
    
    [BaseService post:urlStr headerDictionay:[[UserInfo sharedUserInfo] getHeaderDic]  timeout:SERVICETIMEOUT success:^(id responseObject) {
        NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingAllowFragments error:nil removingNulls:YES ignoreArrays:NO];
        successBlock(dict);
    } fail:^(NSError *error) {
        failBlock(error);
    }];
}

#pragma mark - 查看成交详细
- (void)entrustLog:(NSDictionary *)parDict success:(successResponseBlock)successBlock fail:(failResponseBlock)failBlock {
    
    NSString * para = [parDict toHttpUrlPara];
    NSString * urlStr = [NSString stringWithFormat:@"%@/trade/entrustLog.do?%@",BaseHttpUrl,para];
    
    [BaseService post:urlStr headerDictionay:[[UserInfo sharedUserInfo] getHeaderDic]  timeout:SERVICETIMEOUT success:^(id responseObject) {
        NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingAllowFragments error:nil removingNulls:YES ignoreArrays:NO];
        successBlock(dict);
    } fail:^(NSError *error) {
        failBlock(error);
    }];
}

#pragma mark - 最近成交记录
- (void)entrustInfo:(NSDictionary *)parDict success:(successResponseBlock)successBlock fail:(failResponseBlock)failBlock {
    
    NSString * para = [parDict toHttpUrlPara];
    NSString * urlStr = [NSString stringWithFormat:@"%@/trade/entrustInfo.do?%@",BaseHttpUrl,para];
    
    [BaseService post:urlStr headerDictionay:[[UserInfo sharedUserInfo] getHeaderDic]  timeout:SERVICETIMEOUT success:^(id responseObject) {
        NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingAllowFragments error:nil removingNulls:YES ignoreArrays:NO];
        successBlock(dict);
    } fail:^(NSError *error) {
        failBlock(error);
    }];
}

#pragma mark - 获取买卖7档数据
- (void)realorder:(NSDictionary *)parDict success:(successResponseBlock)successBlock fail:(failResponseBlock)failBlock {
    
    NSString * para = [parDict toHttpUrlPara];
    NSString * urlStr = [NSString stringWithFormat:@"%@/api/v1/realorder?%@",SevenLevelDataUrl,para];
    
    [BaseService get:urlStr dictionay:nil timeout:SERVICETIMEOUT success:^(id responseObject) {
        NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingAllowFragments error:nil removingNulls:YES ignoreArrays:NO];
        successBlock(dict);
    } fail:^(NSError *error) {
        failBlock(error);
    }];
}

@end
